﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BalanceCenter_AdminUserList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {        
        isRequestLogin = true;                                  //是否需要登录
        isAtFramePageLogin = true;                              //是框架页
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url        
        RequestCompetences = Competences.BuildCompetencesList(Competences.MemberManagement);//页面权限

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {
        DataTable dt = new DAL.Views.V_Customer().Open("", "CustomerTypeID < 11", "ID");

        if (dt == null)
        {
            return;
        }

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
    }

    protected void g_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {

        }
    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }

    protected void btnSerch_Click(object sender, EventArgs e)
    {
        if (this.tbSerchUserName.Text.Trim().Equals(""))
        {
            Shove._Web.JavaScript.Alert(this, "请输入要搜索的会员ID");

            return;
        }

        Customer customer = new Customer(_Site.ID);
        string ReturnDescription = "";
        int ResultValue = 0;
        int Result = 0;

        if (ddlType.SelectedValue == "1")
        {
            customer.CustomerNO = tbSerchUserName.Text.Trim();

            Result = customer.GetCustomerInformationByNO(ref ReturnDescription);
        }
        else
        {
            customer.CustomerName = tbSerchUserName.Text.Trim();

            Result = customer.GetCustomerInformationByName(ref ReturnDescription);
        }

        if (Result == -1)
        {
            Shove._Web.JavaScript.Alert(this, "此会员不存在");
            return;
        }

        if (ResultValue < 0)
        {
            Shove._Web.JavaScript.Alert(this, ReturnDescription);
            return;
        }

        DataTable dt = new DAL.Views.V_Customer().Open("", "[ID] = " + customer.ID, "");

        if (dt == null)
        {
            return;
        }

        gPager.PageIndex = 0;

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
    }

    protected void btnSerchAll_Click(object sender, EventArgs e)
    {
        gPager.PageIndex = 0;

        BindData();
    }

    protected void g_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            long ID = Shove._Convert.StrToLong(e.Item.Cells[0].Text, -1);
          //  string ReturnDescription = "";

            if (e.CommandName == "Del")
            {
                //if (DAL.Procedures.P_DelUser(ID, ref ReturnDescription) < 0)
                //{
                //    Shove._Web.JavaScript.Alert(this.Page, ReturnDescription);

                //    return;
                //}

                Shove._Web.JavaScript.Alert(this.Page, "删除成功");
            }

            BindData();
        }
    }
}
